package com.tql.mall.product.controller;

import com.tql.mall.model.product.BaseAttrInfo;
import com.tql.mall.model.product.SkuInfo;
import com.tql.mall.model.product.SpuPoster;
import com.tql.mall.model.product.SpuSaleAttr;
import com.tql.mall.product.service.SkuService;
import com.tql.mall.product.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Author: tyk
 * @Date: 2023/5/22 17:55
 * @Description:
 */
@RestController
@RequestMapping("api/product/inner")
@Api(description = "service-product对内暴露接口")
public class ProductApiController {

    @Autowired
    private SkuService skuService;

    @Autowired
    private SpuService spuService;

    /**
     * 根据skuId查询sku信息和图片列表
     */
    @GetMapping("getSkuInfo{skuId}")
    @ApiOperation("根据skuId查询sku信息和图片列表")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {
        return skuService.getSkuInfo(skuId);
    }


    /**
     * 根据skuId查询实时价格
     */
    @GetMapping("getSkuPrice{skuId}")
    @ApiOperation("根据skuId查询实时价格")
    public BigDecimal getSkuPrice(@PathVariable Long skuId) {
        return skuService.getSkuPrice(skuId);
    }


    /**
     * 根据skuId和spuId获取销售属性数据
     */
    @GetMapping("getSpuSaleAttrList{skuId}/{spuId}")
    @ApiOperation("根据skuId和spuId获取销售属性数据")
    public List<SpuSaleAttr> getSpuSaleAttrList(@PathVariable Long skuId, @PathVariable Long spuId) {
        return spuService.getSpuSaleAttr(skuId, spuId);
    }

    /**
     * 根据spuId获取销售属性值ID与skuId的映射
     */
    @GetMapping("getSkuValueIdsMap/{spuId}")
    @ApiOperation("根据spuId获取销售属性值ID与skuId的映射")
    public Map<String, Long> getSkuValueIdsMap(@PathVariable Long spuId) {
        return skuService.getSkuValueIdsMap(spuId);
    }

    /**
     * 根据sku查询海报信息
     */
    @GetMapping("getSpuPosterList/{spuId}")
    @ApiOperation("根据sku查询海报信息")
    public List<SpuPoster> getSpuPosterList(@PathVariable Long spuId) {
        return spuService.getSpuPosterList(spuId);
    }

    /**
     * 根据skuId获取平台属性集合
     */
    @GetMapping("getBaseAttrInfoList/{skuId}")
    @ApiOperation("根据skuId获取平台属性集合")
    public List<BaseAttrInfo> getBaseAttrInfoList(@PathVariable Long skuId) {
        return skuService.getBaseAttrInfoList(skuId);
    }

}
